<?php
// +----------------------------------------------------------------------
// | ThinkBLOG (Build on ThinkPHP)
// +----------------------------------------------------------------------
// | @link ( http://www.yurnero.net )
// +----------------------------------------------------------------------
// | @licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | @author nicholas <nicholasinlove@126.com>
// +----------------------------------------------------------------------
// | $Id: BaseAction.class.php 144 2012-04-27 08:53:39Z nicholasinlove1986@gmail.com $
// +----------------------------------------------------------------------


class BaseAction extends Action {
	
	public $r;
	public $v;
	public $_users;
	public $_hasLogin = NULL;
	
	public function _initialize() {
		
		$t = ThinkBLOG::getInstance ();
		$t->init ();
		$this->r = Request::getInstance ();
		$this->v = new Validate ();
		
		global $_T;
		$this->_users = $_T ['users'];
	}
	
	public function submitcheck($submit = '') {
		if (! $submit && $this->r->formhash == FORMHASH) {
			return true;
		}
		return false;
	}
	
	public function hasLogin() {
		if (NULL !== $this->_hasLogin) {
			return $this->_hasLogin;
		} else {
			if ($this->_users ['userid']) {
				return ($this->_hasLogin = true);
			}
			return ($this->_hasLogin = false);
		}
	}
	
	public function getErrorNotice($name, $type = 1) {
		$notice = '';
		$tag = $type ? '<br />' : '\r\n';
		
		if (is_array ( $name )) {
			foreach ( $name as $key => $row ) {
				$notice .= $row . $tag;
			}
		} else {
			$notice = $name;
		}
		return substr ( $notice, 0, $notice - strlen ( $tag ) );
	}
	
	public function _empty() {
		//TODO
		redirect ( C ( 'ERROR_PAGE' ) );
	}

}